@using BTCPayServer.Abstractions.Contracts
@using Microsoft.AspNetCore.Mvc.TagHelpers
@inject IFileService FileService
@model IndexViewModel
@{
    ViewData.SetLayoutModel(new LayoutModel("Account", StringLocalizer["Update your account"])
        .SetCategory(nameof(ManageNavPages)));
    var canUpload = await FileService.IsAvailable();
}

<form method="post" enctype="multipart/form-data">
    <div class="sticky-header">
        <h2>@ViewData["Title"]</h2>
		<button id="page-primary" text-translate="true" type="submit" class="btn btn-primary">Save</button>
    </div>
    <partial name="_StatusMessage" />
    <div class="col-xxl-constrain col-xl-8">
        @if (!ViewContext.ModelState.IsValid)
        {
            <div asp-validation-summary="All" class="@(ViewContext.ModelState.ErrorCount.Equals(1) ? "no-marker" : "")"></div>
        }
        <div class="form-group">
            <div class="d-flex align-items-center justify-content-between gap-3">
                <label asp-for="Email" class="form-label"></label>
                @if (Model.RequiresEmailConfirmation)
                {
                    <button asp-action="SendVerificationEmail" class="d-inline-flex align-items-center gap-1 btn btn-link p-0">
                        <vc:icon symbol="actions-email" />
                        <span text-translate="true">Send verification email</span>
                    </button>
                }
                else if (Model.EmailConfirmed)
                {
                    <span class="d-inline-flex align-items-center gap-1 text-success">
                        <vc:icon symbol="checkmark" />
                        <span text-translate="true">confirmed</span>
                    </span>
                }
            </div>
            <input asp-for="Email" class="form-control" />
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="Name" class="form-label"></label>
            <input asp-for="Name" class="form-control" />
            <span asp-validation-for="Name" class="text-danger"></span>
        </div>
        @if (canUpload)
        {
            <div class="form-group">
                <div class="d-flex align-items-center justify-content-between gap-2">
                    <label asp-for="ImageFile" class="form-label"></label>
                    @if (!string.IsNullOrEmpty(Model.ImageUrl))
                    {
                        <button type="submit" class="btn btn-link p-0 text-danger" name="RemoveImageFile" value="true">
                            <vc:icon symbol="cross" />
                            <span text-translate="true">Remove</span>
                        </button>
                    }
                </div>
                <div class="d-flex align-items-center gap-3">
                    <input asp-for="ImageFile" type="file" class="form-control flex-grow">
                    @if (!string.IsNullOrEmpty(Model.ImageUrl))
                    {
                        <img src="@Model.ImageUrl" alt="@StringLocalizer["Profile Picture"]" class="profile-picture"/>
                    }
                </div>
                <span asp-validation-for="ImageFile" class="text-danger"></span>
            </div>
        }
        <h3 class="mt-5 mb-4" text-translate="true">Delete Account</h3>
        <div id="danger-zone">
            <a id="delete-user" class="btn btn-outline-danger mb-5" data-confirm-input="@StringLocalizer["Delete"]" data-bs-toggle="modal" data-bs-target="#ConfirmModal" asp-action="DeleteUserPost" data-description="@StringLocalizer["This action will also delete all stores, invoices, apps and data associated with the user."]" text-translate="true">Delete Account</a>
        </div>
    </div>
</form>
<partial name="_Confirm"
         model="@(new ConfirmModel(StringLocalizer["Delete user"], StringLocalizer["The user will be permanently deleted. This action will also delete all stores, invoices, apps and data associated with your user."], StringLocalizer["Delete"], actionName: nameof(BTCPayServer.Controllers.UIManageController.DeleteUserPost)))"/>

@section PageFootContent {
    <partial name="_ValidationScriptsPartial"/>
}
